FlyTalk.views.NotificationView = Ext.extend(Ext.Panel, {

	scroll: true,
    initComponent: function () {
		
    	this.backButton = new Ext.Button({
			text: 'Back',
			ui: 'back',
			handler: this.backButtonTap,
			scope: this
		});
    	
		this.toolbar = new Ext.Toolbar({
			title: 'Notifications',
			doc: 'top',
			layout: 'hbox',
			items: [
			    this.backButton,
				{xtype: 'spacer'},
			]
		});
		
		// back button on toolbar
		this.noteButton = new Ext.Button({
			text: 'Close Notifications',
			ui: 'light',
			dock: 'bottom',
			handler: this.noteButtonTap,
			//badgeText: 3,
			align: 'stretch',
			width: 320,
			scope: this
		});
		
		this.dockedItems = [this.toolbar, 
		                    this.noteButton,
		                    ];
		
		Ext.regModel('NoteModel', {
			fields: [
				{name: 'id', type: 'int'},
				{name: 'uid', type: 'int'},
				{name: 'thread_id', type: 'int'},
				{name: 'type', type: 'string'},
				{name: 'text', type: 'string'},
				{name: 'read', type: 'string'},
			]
		});
		
		this.noteStore = new Ext.data.JsonStore({
			model : 'NoteModel',
//			sorters: 'read',
//			getGroupString: function(record){
//				record.get('read');
//			}
			/*
			data: [
				{id: 1, uid: 4, thread_id: 62, type: 'replied', text: 'help me', read: 'unread'},
				{id: 1, uid: 4, thread_id: 62, type: 'replied', text: 'help me', read: 'unread'},
			],*/
		});
			
		this.list = new Ext.List({
			itemTpl : "<div style='font-size: small' class='note_{read}'><b>{read}:</b> {text}</div>",
			store: this.noteStore,
			scroll: true,
			//grouped: true,
			fullscreen: true,
			listeners:{
				itemTap: function(dv, index, item, evt){
					var type = FlyTalk.views.NotificationView.noteStore.getAt(index).data.type;
					alert('work in progress');
					
					if(type == 'announced' || type == 'replied'){ // go to reply
						//alert('clicked on announced or replied. work in progress...');
					}else if(type == 'help'){ // go to help
						//alert('clicked on help...');
						
						/*
						Ext.dispatch({
				            controller: FlyTalk.controllers.dbController,
				            action: 'getMixedPosts',
				            title: 'My Talk',
				            tab1: 'Activity',
				            tab2: 'Help Out',
				            method1: 'getMyPost',
				            method2: 'getHelpList', //todo: change this!
				            numtabs: 2,
						}); */ //TODO: set to help out 
					}else if(type == 'reviewed'){ // open review
						//alert('clicked on announced or replied. work in progress...');
					}	
				},
			}			
		});

		this.items = [this.list];
		
		FlyTalk.views.NotificationView.superclass.initComponent.call(this);
        
    },
    
    backButtonTap: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openHome'
        });
    },
    
    noteButtonTap: function () {
    	FlyTalk.views.HomeView.noteButton.setBadge("");
    	FlyTalk.views.mainView.setActiveItem(FlyTalk.views.HomeView, {type: 'slide', direction: 'down'});
    },

});